package com.bonc.rms.config;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.bonc.odk.logmanager.LogManager;
import com.bonc.odk.system.PathUtil;
import com.bonc.rms.constant.Constant;



public class Config {
	
	public static String ELASTICSEARCH_IP;

	public static int ELASTICSEARCH_PORT;
	
	public static String ELASTICSEARCH_NAME;

	public static String ELASTICSEARCH_INDEX;

	public static String ELASTICSEARCH_TYPE;
	

	static {
		Properties properties = new Properties();
		try (InputStream input = new BufferedInputStream(new FileInputStream(
				PathUtil.getConfigDirPath() + File.separator
						+ "application.properties"))) {
			properties.load(input);
			
			ELASTICSEARCH_IP = properties.getProperty(
					Constant.ELASITCSEARCH_IP,
					Constant.ELASITCSEARCH_IP_VALUE);
			ELASTICSEARCH_PORT = Integer.parseInt(properties.getProperty(
					Constant.ELASITCSEARCH_PORT,
					Constant.ELASITCSEARCH_PORT_VALUE));
			
			ELASTICSEARCH_NAME = properties.getProperty(
					Constant.ELASTICSEARCH_NAME,
					Constant.ELASITCSEARCH);
			ELASTICSEARCH_INDEX = properties.getProperty(
					Constant.ELASTICSEARCH_INDEX,
					Constant.ELASTICSEARCH_INDEX_VALUE);
			ELASTICSEARCH_TYPE = properties.getProperty(
					Constant.ELASTICSEARCH_TYPE,
					Constant.ELASTICSEARCH_TYPE_VALUE);
		} catch (IOException e) {
			LogManager.Exception(
					"System Config Exception in package config : ", e);
		} catch (Exception e) {
			LogManager.Exception("System Config loaded failed! : ", e);
		}
	}
}
